<?php

namespace app\index\controller;

use service\FeishuService;
use service\GuardService;
use service\LadderService;
use think\Controller;
use think\Cache;
use think\Db;
use think\Exception;

class Jumpvisitor extends Controller
{
    public function index(){
        $id = $this->request->param("id");
        $visitor_id = Cache::store('redis')->get($id);
        $where = [];
        if(empty($visitor_id)){
            $where['visitorkey'] = $id;
        }
        else{
            $where['id'] = $visitor_id;
        }
        $visitorinfo = db("visitor")->where($where)->find();
        $state = 1;
        $ctime = time();
        if($visitorinfo['state'] == 2 || $visitorinfo['visitoretime'] < $ctime){
            $state = 2;
        }
        //dump($visitorinfo);exit;
        //访客权限
        $ladderqrcodeinfo = LadderService::instance()->getqrcode(FeishuService::instance()->GetUserfloorinfo($visitorinfo['user_id']));
        //dump($ladderqrcodeinfo);exit;
        //获取门禁二维码信息
        $guardqrcodeinfo = GuardService::instance()->getqrcode($visitorinfo['user_id']);
        //dump($guardqrcodeinfo);exit;
        $unifyqrcode = $ladderqrcodeinfo['enceypted'].LadderService::LGSPLIT.$guardqrcodeinfo;
        //dump($unifyqrcode);exit;
        $this->assign("unifyqrcode",$unifyqrcode);
        $this->assign("ladderqrcodeinfo",$ladderqrcodeinfo);
        $this->assign("visitorinfo",$visitorinfo);
        $this->assign("state",$state);
        return $this->fetch();
    }
}